﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Ordens.Communication.Bovespa.Custodia.Custodia;
using Sinacor.UI.Bovespa.Ordens.Communication.Translator;
using Sinacor.UI.Bovespa.Ordens.Model;



namespace Sinacor.UI.Bovespa.Ordens.Communication
{
    public class Custodia : BaseCommunication
    {

        #region Construtor

        public Custodia(SessionInformation session)
            : base(session)
        {

        }

        #endregion


        public Model.PosicaoCustodia ConsultarPosicaoCustodia(Model.Parameter.ConsultarPosicaoCustodiaRequest pConsultar)
        {
            Model.PosicaoCustodia retorno = null;
            ICustodia servico = null;

            try
            {
                using (ServiceInstance<ICustodia> serviceManager = new ServiceInstance<ICustodia>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    retorno = new Translator.TranslatorPosicaoCustodiaResponseOrdem().Translate(servico.ConsultarPosicaoCustodia(new Translator.TranslatorConsultarPosicaoCustodiaRequest().Translate(pConsultar)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

            return retorno;
        }
    }
}
